package teachnotes.guides.client;

import teachnotes.guides.compute.Compute;

import java.math.BigDecimal;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.function.Supplier;
import java.util.logging.Logger;

/**
 * 客户端类
 * @author xiaoming
 * @date 2020-06-25 13:56
 */
public class ComputePi {
    private static Logger log = Logger.getLogger(ComputePi.class.getSimpleName());

    public static void main(String[] args) {
        // 示例: 计算机计算 PI值

        if (null == System.getSecurityManager()) {
            System.setSecurityManager(new SecurityManager());
        }
        try {
            String name = "Compute";
            // null 即 localhost
            Registry registry = LocateRegistry.getRegistry();
            Compute skeleton = (Compute) registry.lookup(name);

            Pi task = new Pi(12 );

            BigDecimal pi = skeleton.executeTask(task);

            log.info((Supplier<String>) pi);
        } catch (Exception e) {
            log.warning(e.getMessage());
            e.printStackTrace();
        }

    }
}
